#!/bin/bash

BASEDIR="$(cd "$(dirname "$0")"; pwd)"

cd $BASEDIR/bin

tname=$(echo $@ | awk '{print $2}')
outlog="output-$tname-$$.log"

./GPU-perf-cuda $@ > $outlog 2>&1
ret=$?
if [ $ret != "0" ]; then
    echo "run fail, ret=<$ret>"
    exit $ret
fi

cat $outlog | grep COUNT >&2
keywords="Case              | type           | Weight   | Value    | Unit      |  Result"
state=$(grep -A 1 "$keywords" $outlog | tail -n 1 | awk '{print $NF}')
if [ "$state" != "success" ]; then
    echo "selfcheck error: state=<$state>" 1>&2
    exit 1
fi

exit 0
